package pl.diagnoser.server.persistance.map;

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import pl.diagnoser.client.dto.SymptomDTO;
import static javax.persistence.GenerationType.IDENTITY;

@Entity
@Table(name = "T_SYMPTOM")
public class Symptom implements Serializable {

        private static final long serialVersionUID = 2569133686270539403L;
        private Long id;
        private String symptomName;
        private Double symptomConfidence;
        private Estimate estimate;
        
        public Symptom() {}
        public Symptom( Estimate estimate, String symptomName, Double symptomConfidence ) {
                this.estimate = estimate;
                this.symptomName = symptomName;
                this.symptomConfidence = symptomConfidence;
        }
        public Symptom( SymptomDTO symptom, Estimate estimate ) {
                this.symptomName = symptom.getSymptomName();
                this.symptomConfidence = symptom.getSymptomConfidence();
                this.estimate = estimate;
        }
        
        @Id
        @GeneratedValue(strategy = IDENTITY)
        @Column( name="SMM_ID", unique = true, nullable = false )
        public Long getId() {
                return this.id;
        }
        
        public void setId( Long id ) {
                this.id = id;
        }
        
        
        @Column( name="SMM_NAME", unique = false, nullable = false, length = 45 )
        public String getSymptomName() {
                return symptomName;
        }
        
        public void setSymptomName( String symptomName ) {
                this.symptomName = symptomName;
        }
        
        @Column( name="SMM_CONFIDENCE", unique = false, nullable = false  )
        public Double getSymptomConfidence() {
                return this.symptomConfidence;
        }
        
        public void setSymptomConfidence( Double symptomConfidence ) {
                this.symptomConfidence = symptomConfidence;
        }
        
        @ManyToOne()
        @JoinColumn( name="SMM_EST_ID", nullable = false , unique = true )
        public Estimate getEstimate() {
                return estimate;
        }
        
        public void setEstimate( Estimate estimate ) {
                this.estimate = estimate;
        }
        
        public String toString() {
                return new String( symptomName + ": " + symptomConfidence );
        }
        
        public String toXMLString() {
                
                String result = new String();
                result = "<symptom>";
                result += "<id>" + this.id + "</id>";
                result += "<symptomName>" + this.symptomName + "</symptomName>";
                result += "<symptomConfidence>" + this.symptomConfidence + "</symptomConfidence>";
                result += "</symptom>";
                return result;
        }
}